﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cofe.Core.Logger
{
    public class EventLog<T> : IEventLog<T>
        where T : EventArgs
    {
        #region Constructor

        public static EventLog<T> CreateEvent(string sender, T eventArgs)
        {
            string userName = null;

            var securityManager = CofeServices.SecurityManager;
            if (securityManager != null)
            {
                var user = CofeServices.SecurityManager.CurrentPrincipal;
                userName = user == null || user.Identity == null ? "" : user.Identity.Name;
            }

            return new EventLog<T>()
            {
                UtcTime = DateTime.UtcNow,
                Sender = sender,
                UserId = userName,
                EventArgs = eventArgs
            };
        }

        #endregion

        #region Public Properties

        public DateTime UtcTime { get; set; }
        public string Sender { get; set; }
        public string UserId { get; set; }
        public T EventArgs { get; set; }
        EventArgs IEventLog.EventArgs { get { return EventArgs; } }

        #endregion

    }
}
